package leetcode2;
class MyRunable1 implements Runnable{
    @Override
    public void run() {
        while (!Thread.interrupted()){
            System.out.println(Thread.currentThread().getName()+":别管我，我忙着转账呢！");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
                System.out.println(Thread.currentThread().getName()+"有内鬼，终止交易");
                break;
            }
        }
        System.out.println(Thread.currentThread().getName()+":啊!险些耽误了大事");
    }
}
class MyRunnable implements Runnable {
    @Override
    public void run() {
        for (int i = 0; i < 10; i++) {
            System.out.println(Thread.interrupted());
        }
    }
}
public class LeetCodeMain139 {
    public static void main(String[] args) {
        MyRunnable target = new MyRunnable();
        Thread thread = new Thread(target, "李四");
        thread.start();
        thread.interrupt();
    }
    public static void main1(String[] args) throws InterruptedException {
        MyRunable1 runable1=new MyRunable1();
        Thread thread=new Thread(runable1,"李四");
        System.out.println(Thread.currentThread().getName()+":让李四开始转账");
        thread.start();
        Thread.sleep(10*1000);
        System.out.println(Thread.currentThread().getName()+":老板来电话了，得赶紧通知李四对方是个骗子");
        thread.interrupt();
    }
}